package com.llxy.web.controller.worker;
import com.llxy.common.annotation.Log;
import com.llxy.common.core.controller.BaseController;
import com.llxy.common.core.domain.AjaxResult;
import com.llxy.common.core.domain.entity.SysRole;
import com.llxy.common.enums.BusinessType;
import com.llxy.worker.domain.EmployerSupport;
import com.llxy.worker.service.EmployerSupportService;
import com.llxy.worker.service.impl.EmployerSupportServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
* (t_employer_support)表控制层
*
* @author 马瑞龙
*/
@RestController
@RequestMapping("/client")
public class EmployerSupportController extends BaseController {
    /**
    * 服务对象
    */
    @Autowired
    private EmployerSupportService employerSupportService;


    /**
     * 聘请护工
     */
    @PreAuthorize("@ss.hasPermi('client:support:deliver')")
    @Log(title = "聘请护工", businessType = BusinessType.INSERT)
    @PostMapping("/support/{id}")
    public AjaxResult deliver(@PathVariable Integer id)
    {
        EmployerSupport employerSupport = new EmployerSupport();
        employerSupport.setEmployerId(getUserId().intValue());
        employerSupport.setSupportId(id);
        EmployerSupport es = employerSupportService.selectByEmployerIdAndSupportId(employerSupport);
        if (null != es){
            return error("您已经聘请过该护工了~");
        }
        employerSupport.setStatus(0);
        return toAjax(employerSupportService.insertSelective(employerSupport));
    }

    /**
     * 历史聘请护工列表
     */
    @PreAuthorize("@ss.hasPermi('client:support:deliver')")
    @GetMapping("/support/history")
    public AjaxResult deliverHistory()
    {
        return success(employerSupportService.deliverHistory(getUserId()));
    }

    /**
     * 历史聘请护工列表
     */
    @GetMapping("/support/count")
    public AjaxResult count()
    {
        return success(employerSupportService.count(getUserId()));
    }

}
